package com.greendeliver.activities;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.RatingBar;
import android.widget.TextView;

import com.example.test.R;
import com.greendeliver.activities.base.BaseActivity;
import com.greendeliver.business.EventManager;

public class VoteActivity extends BaseActivity {

	private String				ID_EVENT;
	private String				APPLICATION_NAME;
	private float				APPLICATION_RATE;
	private float				USER_RATE;
	private int					APPLICATION_NBVOTE;

	private static final String	TAG_ID		= "ID_event";
	private static final String	TAG_NAME	= "name_event";
	private static final String	TAG_VOTE	= "vote_event";
	private static final String	TAG_NBVOTE	= "nb_vote_event";
	private TextView			textTitleEvent;
	private Button				bt1;

	private RatingBar			ratingbar1;

	@Override
	protected void onCreate( Bundle savedInstanceState ) {
		super.onCreate( savedInstanceState );
		setFullscreen();
		setContentView( R.layout.activity_vote );

		Intent i = getIntent();
		this.ID_EVENT = i.getStringExtra( TAG_ID );
		this.APPLICATION_NAME = i.getStringExtra( TAG_NAME );
		this.APPLICATION_RATE = Float.parseFloat( i.getStringExtra( TAG_VOTE ) );
		this.APPLICATION_NBVOTE = Integer.parseInt( i.getStringExtra( TAG_NBVOTE ) );
		this.ratingbar1 = (RatingBar) findViewById( R.id.ratingBaruser );
		this.bt1 = (Button) findViewById( R.id.buttonvote );
		this.USER_RATE = 0;

		this.textTitleEvent = (TextView) findViewById( R.id.TitleEvent );
		textTitleEvent.setText( APPLICATION_NAME );

		// view products click event
		bt1.setOnClickListener( new View.OnClickListener()
		{
			@Override
			public void onClick( View view ) {
				USER_RATE = ratingbar1.getRating();
				EventManager em = new EventManager();

				em.rating_an_event( ID_EVENT, USER_RATE, APPLICATION_RATE, APPLICATION_NBVOTE );

				// Serizable object
				em.addSerializableVoteByEvent_BA( VoteActivity.this, Integer.parseInt( ID_EVENT ), APPLICATION_NAME );

				// Starting new intent
				/*Intent in = new Intent( getApplicationContext(),
						EventDetailActivity.class );
				// sending id to next activity
				in.putExtra( TAG_ID, ID_EVENT );

				// starting new activity and expecting some response back
				startActivity( in );*/

				setResult( 0 );
				finish();
			}
		} );
	}
}
